package com.xingshang.controller;

import com.xingshang.pojo.Playlist;
import com.xingshang.service.PlaylistService;
import com.xingshang.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@CrossOrigin
@RequestMapping("playlist")
public class PlaylistController {

    @Autowired
    PlaylistService playlistService;


    @PostMapping("add")
    public Result addPlaylist(@RequestBody Playlist playlist, @RequestHeader String token) {
        Result result = playlistService.addPlaylist(playlist, token);
        return result;
    }

    @PostMapping("del")
    public Result delPlaylist(@RequestBody HashMap<String, Integer> data, @RequestHeader String token) {
        System.out.println(data);
        System.out.println("playlistid = " + data.get("playlistid"));
        // 调用服务层进行删除操作
        Result result = playlistService.del(data.get("playlistid"), token);
        return result;
    }


    @GetMapping("")
    public Result get(@RequestHeader String token) {
        Result result = playlistService.getplaylist(token);
        return result;
    }

    /**
     * 清空用户播放列表
     * @param token
     * @return
     */
    @DeleteMapping("/clear")
    public Result delAll(@RequestHeader String token) {
        Result result = playlistService.delAll(token);
        return result;
    }
}
